package com.nicolas.web.tag;

import java.util.List;
import java.util.Map;

import com.nicolas.web.tag.ui.table.Header;

public class SuyUiTag {

	public static String table(String css, List<Header> headers,
			List<Map<?, ?>> data) {

		StringBuffer tpl = new StringBuffer();
		tpl.append("<table class='" + css + "'>");

		if (headers != null && headers.size() > 0) {
			tpl.append("<thead><tr>");
			for (Header header : headers) {
				tpl.append("<th>" + header.getTitle() + "</th>");
			}
			tpl.append("</tr></thead>");
		}
		if (data != null && data.size() > 0) {
			tpl.append("<tbody>");
			for (Map<?, ?> map : data) {
				tpl.append("<tr>");
				if (headers != null && headers.size() > 0) {
					for (Header header : headers) {
						tpl.append("<td>" + map.get(header.getIndex())
								+ "</td>");
					}
				}
				tpl.append("</tr>");
			}
			tpl.append("</tbody>");
		}
		tpl.append("</table>");
		return tpl.toString();
	}

	public static void main(String[] args) {
		System.out.println(table("", null, null));
	}
}
